package com.gitee.sidihuo.platform.model;

import com.gitee.sidihuo.utils.base.IResponseCodeMsg;
import com.gitee.sidihuo.utils.util.MdcUtils;

public class ApiResult<T> {

    private T data;
    private boolean isSuccess = true;
    private Integer code = BaseResponseCodeMsg.SUCCESS.getCode();
    private String message = BaseResponseCodeMsg.SUCCESS.getMessage();
    /**
     * 失败原因的备注，页面不展示，用于开发测试联调
     */
    private String developMsg;
    private String requestNo;

    public ApiResult<T> data(T data) {
        this.data = data;
        return this;
    }

    public static ApiResult ok() {
        ApiResult r = new ApiResult();
        r.setSuccess(true);
        r.setRequestNo(MdcUtils.getLogTrace());
        return r;
    }

    public static ApiResult ok(Object data) {
        ApiResult r = new ApiResult();
        r.setSuccess(true);
        r.setData(data);
        r.setRequestNo(MdcUtils.getLogTrace());
        return r;
    }

    public static ApiResult error(IResponseCodeMsg respCodeEnum) {
        ApiResult r = new ApiResult();
        r.setSuccess(false);
        r.setCode(respCodeEnum.getCode());
        r.setMessage(respCodeEnum.getMessage());
        r.setRequestNo(MdcUtils.getLogTrace());
        return r;
    }

	public static ApiResult error(Integer code, String message,String developMsg) {
		ApiResult r = new ApiResult();
		r.setSuccess(false);
		r.setCode(code);
		r.setMessage(message);
		r.setDevelopMsg(developMsg);
        r.setRequestNo(MdcUtils.getLogTrace());
		return r;
	}

    public static ApiResult error(IResponseCodeMsg respCodeEnum, String developMsg) {
        ApiResult r = new ApiResult();
        r.setSuccess(false);
        r.setCode(respCodeEnum.getCode());
        r.setMessage(respCodeEnum.getMessage());
        r.setDevelopMsg(developMsg);
        r.setRequestNo(MdcUtils.getLogTrace());
        return r;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public boolean isSuccess() {
        return isSuccess;
    }

    public void setSuccess(boolean success) {
        isSuccess = success;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getDevelopMsg() {
        return developMsg;
    }

    public void setDevelopMsg(String developMsg) {
        this.developMsg = developMsg;
    }

    public String getRequestNo() {
        return requestNo;
    }

    public void setRequestNo(String requestNo) {
        this.requestNo = requestNo;
    }

}
